package gcontent.config.node.site;


import java.util.Vector;

import gcontent.config.error.ConfigEx;
import gcontent.config.node.GNode;
import gcontent.config.node.filter.FilterRefNode;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class SiteNode extends GNode {

	private Vector<FilterRefNode> trace_filter = new Vector<FilterRefNode>();

	public Vector<FilterRefNode> getTraceFiltersRef()
	{
		return this.trace_filter;
	}

	public SiteNode(Node node) throws ConfigEx
	{
		NodeList node_list;	
		

		node_list = node.getChildNodes();
		for(int i = 0; node_list.item(i) != null; i++) {
			Node node_c;
			String name;
			
			node_c = node_list.item(i);
			name = node_c.getNodeName();
			if(name.equals("filters")) {
				NodeList refs = node_c.getChildNodes();
				for(int o = 0; refs.item(o) != null; o++) {
					Node node_r;		
					String name_r;
					node_r = refs.item(o);
					name_r = node_r.getNodeName();
					if(name_r.equals("ref")) {
						FilterRefNode filter_ref = new FilterRefNode(refs.item(o));
						if(filter_ref != null)
							filter.add(filter_ref);
					} else if(name_r.charAt(0) != '#')
						throw new ConfigEx("SiteNode : invalid node " + name);
				}
			} else if(name.equals("trace")) {
				NodeList refs = node_c.getChildNodes();
				
				for(int o = 0; refs.item(o) != null; o++) {
					Node node_r;		
					String name_r;
					node_r = refs.item(o);
					name_r = node_r.getNodeName();
					if(name_r.equals("ref")) {
						FilterRefNode filter_ref = new FilterRefNode(refs.item(o));
						if(filter_ref != null)
							trace_filter.add(filter_ref);
					} else if(name_r.charAt(0) != '#')
						throw new ConfigEx("SiteNode : invalid node " + name);
				}				
				
			} else if(name.charAt(0) != '#')
				throw new ConfigEx("SiteNode => unknown node " + name);
		}		
	}
}
